package com.techtransteam.techtransteamWeb.dal.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.techtransteam.techtransteamWeb.dal.entities.Role;

@Repository
public class RoleDAO {
	
    @Autowired
    private SessionFactory sessionFactory;
    
    public Session getCurrentSession(){
    	return sessionFactory.getCurrentSession();
    }

    public void addRole(Role role){
    	getCurrentSession().save(role);
    }
    
    public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@SuppressWarnings("unchecked")
	public List<Role> getAllRoles(){
    	return getCurrentSession().createQuery("from com.techtransteam.techtransteamWeb.dal.entities.Role").list();
    }
}
